import { RouteComponentProps } from 'react-router';
import { onFormMount } from '@formily/core';
import { Form } from '@formily/core/esm/models';
import CreateList from '@/biz-components/hoc-form/checkbox-table-form';
import { apiUrl, FapiaoListConfig } from './service';
import components from '@/components/schema-form-render/schema-components-registed/components-biz';

interface IList extends RouteComponentProps {
  changeSelect: (selected: any) => void;
  type?: string;
  importExcel: () => void;
  refresh: Number;
  oldValue?: any[];
  defaultValue?: any[];
  extraPrams: any;
  rowKey?: string;
}

const List = (props: IList) => {
  const {
    match,
    history,
    changeSelect,
    type,
    importExcel,
    refresh,
    oldValue,
    defaultValue,
    extraPrams = {},
      pageCode,
      pageUrl,
      rowKey,
  } = props;
  /**
   * 重置form字段
   * @param form
   */
  const resetFormFields = (form: Form) => {};
  return (
    <>
      <CreateList
        match={match}
        history={history}
        pageCode={type === 'public' ? pageCode : FapiaoListConfig.SELECT}
        needGroup={true}
        reloadFlag={refresh}
        noModal={true}
        pageApi={type === 'public' ? pageUrl : apiUrl.privatePage}
        components={components}
        rowSelection={{
          onChange: (selectedRowKeys: string[], selectedRows: any[]) => {
            changeSelect(selectedRows);
          },
        }}
        extraPrams={type === 'public' ? {...extraPrams} : {
          ...extraPrams,
          status: 'NotUsed',
        }}
        rowKey={rowKey || 'id'}
        oldValue={oldValue}
        defaultValue={defaultValue}
        formConfigs={{
          effects: () => {
            onFormMount(resetFormFields);
          },
        }}
        events={{
          buttonsEvents: {
            importExcel,
          },
        }}
      />
    </>
  );
};
export default List;
